package cn.kgm.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    public static final String BOOT_TOPIC_EXCHANGE = "boot_topic_exchange";
    public static final String QUEUE_NAME = "boot_queue";

    // 交换机
    @Bean("bootExchange" )
    public Exchange bootExchange() {
        return ExchangeBuilder.topicExchange(BOOT_TOPIC_EXCHANGE).durable(true).build();
    }

    // queue
    @Bean("bootQueue" )
    public Queue bootQueue() {
        return QueueBuilder.durable(QUEUE_NAME).build();
    }

    // 绑定关系
    @Bean
    public Binding bootBinding(@Qualifier("bootQueue" ) Queue queue, @Qualifier("bootExchange" ) Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("boot.#" ).noargs();
    }

}
